import type { BingElements } from '../../../../../../../../types/constants/personalization/bing'
import { ThemeVarService } from '../../../../../../../../lib/abstract/style/theme_var/service'
import {
  PAGE_ELEMENTS,
  SUPPORTED_PLATFORMS,
} from '../../../../../../../../types/constants'
import { SearchCommonStyles } from '../../common'

export class BingWebPage {
  elements: BingElements = PAGE_ELEMENTS[SUPPORTED_PLATFORMS.BING]
  private static instance: BingWebPage
  private readonly themeVarService: ThemeVarService = ThemeVarService.getInstance()
  private readonly searchCommonStyles: SearchCommonStyles = SearchCommonStyles.getInstance()

  /**
   * 获取单例实例
   */
  public static getInstance(): BingWebPage {
    if (!BingWebPage.instance) {
      BingWebPage.instance = new BingWebPage()
    }
    return BingWebPage.instance
  }

  init(): void {
  }

  /**
   * 无搜索结果样式
   */
  noSearchResult(): string {
    return ``
  }

  getMainStyles(): string {
    return `
/* 主内容 */
#b_content {
  position: relative !important;
  background: transparent !important;
  display: flex !important;
  justify-content: center !important;
  padding: 0 !important;
  margin: 0 auto !important;
  padding-top: 41px !important;
  
  /* 结果摘要 */
  #b_topw {
    background: white !important;
    width: fit-content !important;
    padding: ${this.themeVarService.search.resultItem.paddingStandard} !important;
    border-radius: ${this.themeVarService.search.resultItem.borderRadius} !important;
    margin-bottom: ${this.themeVarService.search.resultItem.gap} !important;
    
    #b_wpt_container {
      border-bottom: none !important;
    }
  }
  
  #b_tween {
    /* 搜索结果摘要 */
    #b_tween_searchResults {
      .sb_count {
        color: var(${this.themeVarService.search.default.text}) !important;
      }
    }
  }
  
  /* 搜索结果列表 */
  #b_results {
    ${this.searchCommonStyles.resultContainerStyles()}
    margin-bottom: ${this.themeVarService.search.resultItem.gap} !important;
    
    /* 非结果项，分页占一行并居中 */
    > li.b_pag {
      ${this.searchCommonStyles.resultOtherStyles()}
    }
    
    /* 提示信息 */
    > li.b_msg {
      color: var(${this.themeVarService.search.default.text}) !important;
      background-color: transparent !important;
      
      a {
        color: var(${this.themeVarService.link.default.text}) !important;
      }
    }
    
    /* 隐藏广告分割线 */
    > li#adstop_gradiant_separator {
      display: none !important;
    }

    /* 结果项 */
    > li:not(.b_pag, .b_msg) {
      ${this.searchCommonStyles.resultItemStyles()}
      
      a {
        color: var(${this.themeVarService.link.default.text}) !important;
      }
      
      /* 元数据 */
      .b_tpcn {
        .tptt {
          color: var(${this.themeVarService.search.default.text}) !important;
        }
        .tpmeta {
          .b_tranthis {
            color: #8b68c6 !important;
          }
        }
      }
      
      /* 标题 */
      h2 {
        color: var(${this.themeVarService.search.default.text}) !important;
        
        /* 去掉标题下划线 */
        a {
          text-decoration: none !important;
          font-size: ${this.themeVarService.search.resultItem.titleFontSize} !important;
          
          &:hover {
            color: var(${this.themeVarService.link.default.textHover}) !important;
            
            &::after {
              border-right-color: var(${this.themeVarService.link.default.textHover}) !important;
              border-top-color: var(${this.themeVarService.link.default.textHover}) !important;
            }
          }
          
          &::after {
            border-right-color: var(${this.themeVarService.link.default.text}) !important;
            border-top-color: var(${this.themeVarService.link.default.text}) !important;
          }
        }
      }
      
      /* 大家还在搜 */
      .b_inline_ajax_rs {
        .rslist_title {
          color: var(${this.themeVarService.search.default.text}) !important;
        }
      }
      
      /* 描述*/
      p {
        color: var(${this.themeVarService.search.default.text}) !important;
      }
      
      /* 其他描述 */
      .feeditem_details {
        .feeditem_snippet {
          color: var(${this.themeVarService.search.default.text}) !important;
        }
        
        .feeditem_sourceName {
          background-color: var(${this.themeVarService.message.info.textPrimary}) !important;
          padding: 2px 5px !important;
          border-radius: 4px !important;
        }
      }
      
      .b_caption {
        /* 维基百科 */
        .b_wikiRichcard {
          .wiki_attr {
            span {
              color: var(${this.themeVarService.search.default.text}) !important;
            }
          }
        }
        
        /* 百度百科 */
        .tab-content {
          ul {
            li {
              color: var(${this.themeVarService.search.default.text}) !important;

              div {
                color: var(${this.themeVarService.search.default.text}) !important;
              }
            }
          }
        }
      }
      
      /* 查看更多 */
      .new_see_more_container {
        .new_see_more_line {
          border: none !important;
        }
      }
      
      /* 广告项 */
      &.b_ad {
        div {
          color: var(${this.themeVarService.search.default.text}) !important;
        }

        .b_icondomian {
          color: var(${this.themeVarService.search.default.text}) !important;
        }
        
        .b_attribution {
          cite {
            color: var(${this.themeVarService.search.default.textNeutral}) !important;
          }
        }
      }
      
      &.b_algo {
        .b_caption {
          .b_richcard {
            .tab-head {
              .tab-navl, .tab-navr {
                background-color: transparent !important;
                
                &:hover {
                  svg .sv_ch {
                    fill: var(${this.themeVarService.link.default.textHover}) !important;
                  }
                }
                
                svg .sv_ch {
                  fill: var(${this.themeVarService.link.default.text}) !important;
                }
              }
              
              .tab-menu {
                ul li {
                  background-color: transparent !important;
                  color: var(${this.themeVarService.search.default.text}) !important;
                  
                  &.tab-active {
                    background-color: #d9dffb !important;
                    color: #3c51b4 !important; 
                  }
                }
              }
            }
            
            .tab-content {
              span {
                color: var(${this.themeVarService.search.default.text}) !important;
              }
            }
          }
        }
      }
      
      &.b_ans {
        /* 软件下载 */
        &:has([data-tag="AppSearch.TechInstallables"]) {
          padding: ${this.themeVarService.search.resultItem.paddingStandard} !important;
          
          #imc {
            width: 100% !important;
            #imc_top {
              a.fc {
                &:hover {
                  h2 {
                    color: var(${this.themeVarService.link.default.textHover}) !important;
                    text-decoration: none !important;
                  }
                }
                
                h2 {
                  color: var(${this.themeVarService.link.default.text}) !important;
                }
              }
              
              a#imc_pbtn {
                color: white !important;
              }
            }
          }
        }
        
        /* 相关资讯 */
        #ans_nws {
          .nws_itm_cjk {
            &:hover {
              .itm_cap_cjk p.na_t_news_caption {
                text-decoration: none !important;
              }
            }

            &::before {
              border-bottom-color: var(${this.themeVarService.default.border.colorNeutral}) !important;
            }
            
            .itm_cap_cjk {
              p.na_t_news_caption {
                color: var(${this.themeVarService.link.default.text}) !important;
                
                &:hover {
                  color: var(${this.themeVarService.link.default.textHover}) !important;
                  text-decoration: none !important;
                }
              }
            }
          }
        }

        /* 相关视频 */
        #serpvidans {
          .b_title {
            padding-left: 0 !important;

            h2 {              
              a {
                &:hover {
                  &::after {
                    border-right-color: var(${this.themeVarService.link.default.textHover}) !important;
                    border-top-color: var(${this.themeVarService.link.default.textHover}) !important;
                  }
                }
                
                &::after {
                  border-right-color: var(${this.themeVarService.link.default.text}) !important;
                  border-top-color: var(${this.themeVarService.link.default.text}) !important;
                }
              }
            }
          }
          
          .mmlist {
            [id^="mc_cwvc"] {
              .mc_vtvc {
                border-radius: 0 8px 8px 0 !important;
                
                &:hover {
                  .mc_vtvc_con_rc .mc_vtvc_meta .mc_vtvc_title {
                    color: var(${this.themeVarService.link.default.textHover}) !important;
                    text-decoration: none !important;
                  }
                }
                
                .mc_vtvc_con_rc {
                  border-radius: unset !important;
                  
                  &.onhov {
                    .vrhc , .vrhc .vrhtc {
                      border-radius: unset !important;
                    }
                  }
                  
                  .mc_vtvc_th {
                    .cico {
                      border-radius: unset !important;
                    }
                  }
                  
                  .mc_vtvc_meta {
                    .mc_vtvc_title {
                      color: var(${this.themeVarService.link.default.text}) !important;
                    }
                  }
                }
              }
            }
          }
        }

        /* 大家还在问 */
        #df_listaa {
          div, span {
            color: var(${this.themeVarService.search.default.text}) !important;
          }
          
          .openans_gradient_div {
            background: transparent !important;
          }
          
          .btn.prev {
            left: 12px !important;
          }
          
          .btn.next {
            right: 12px !important;
          }

          .b_slidebar {
            .slide {
              border: 1px solid var(${this.themeVarService.default.border.colorNeutral}) !important;
              box-shadow: none !important;
              margin: 0 4px!important;
              
              &:hover {
                box-shadow: none !important;
                
                .b_algo {
                  text-decoration: none !important;
                  
                  h2 span {
                    color: var(${this.themeVarService.link.default.textHover}) !important;
                  }
                }
              }

              a {
                .df_ansatb {
                  border-color: var(${this.themeVarService.default.border.colorNeutral}) !important;
                }
              }
              
              .b_algo h2 span {
                color: var(${this.themeVarService.link.default.text}) !important;
              }
            }
          }
        }
        
        /* 信息卡片 */
        .qna_tlgacont {
          .qna-mf {
            > div {
              margin: 0 !important;
            }
          }
        }
      }
    }
  }
  
  /* 右侧边栏 */
  aside {
    position: absolute !important;
    right: 100px !important;

    #b_context {
      h2, h3, a, span, .l_ecrd_ftr_txt {
        color: var(${this.themeVarService.search.default.text}) !important;
      }
      
      .lc_expfact_default a:not(.lc_expfact_title) {
          color: var(${this.themeVarService.link.default.text}) !important;
          
          &:hover {
            color: var(${this.themeVarService.link.default.textHover}) !important;
            text-decoration: none !important;
          }
        }
      }
      
      .lite-entcard-blk:not(:last-child):not(.l_ecrd_bkg_bdrls), .l_ecrd_webicons_with_title {
        border-color: var(${this.themeVarService.default.border.colorNeutral}) !important;
      }
      
      /* 相关搜索 */
      a {
        .suggestion_text {
          color: var(${this.themeVarService.search.default.textBase}) !important;
        }
      }
    }
  }
}
`
  }
}
